#include <iostream>
using namespace std;


int find(int *f,int n){
	if(f[n] == n)
		return n;
	f[n] = find(f,f[n]);
	return f[n];
}

int main(){
	int n,m;
	cin>>n>>m;
	int f[n];
	for(int i=0;i<n;i++)
		f[i] = i;
	
	for(int j=0;j<m;j++){
		int z,x,y;
		cin>>z>>x>>y;
		x--;y--;
		if(z == 1)
			f[find(f,x)] = find(f,y);
		else{
			x = find(f,x);
			y = find(f,y);
			if(x == y)
				cout<<"Y"<<endl;
			else
				cout<<"N"<<endl;
		}
	}
	return 0;
}
